﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace MusicPlayer
{
    public partial class CustomListBox : Panel
    {
        private List<CustomListBoxItem> _items;
        public CustomListBox()
        {
            _items = new List<CustomListBoxItem>();
            InitializeComponent();
            
        }

        public event EventHandler ItemClick
        {
            add
            {
                base.Events.AddHandler(new object(), value);
            }
            remove
            {
                base.Events.RemoveHandler(new object(), value);
            }
        }

        public void AddItem(string name)
        {
            CustomListBoxItem item = new CustomListBoxItem(name);
            int y = _items.Count * (item.Height + 5) + 10;
            item.Location = new Point(10, y);
            item.Size = new Size(this.Width - this.Padding.Left - this.Padding.Right, 50);
            item.Dock = DockStyle.None;
            item.MouseHover += Item_MouseHover;
            item.Click += Item_Click;
            this.Controls.Add(item);
            _items.Add(item);
        }

        private void Item_Click(object sender, EventArgs e)
        {
            MessageBox.Show(sender.GetType().FullName);
        }

        private void Item_MouseHover(object sender, EventArgs e)
        {
            // MessageBox.Show(sender.GetType().FullName);
        }

        public void Active(int index)
        {
            if (index >= 0 && index < Controls.Count)
            {
                ((CustomListBoxItem)Controls[index]).Active();
            }
        }

        public void UnActive(int index)
        {
            if (index >= 0 && index < Controls.Count)
            {
                ((CustomListBoxItem)Controls[index]).UnActive();
            }
        }
    }
}
